﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Fis.Win.Utils
{

    public interface IDataTrans
    {
        void ToXls(string path);
        string FromXls(string path);
    }
    
    /// <summary>
    /// 数据转换工具
    /// </summary>
    public class DataTransUtils
    {
        /// <summary>
        /// 读取sheet
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="sheet"></param>
        /// <returns></returns>
        public static DataTable ReadSheet(string uri, string sheet, ref string error)
        {
            try
            {
                var dc = Agile.Engine.Data.DataContext.ExcelContext(uri);
                var name = string.Format("[{0}$]", sheet);
                return dc.DefaultModel.QueryTable(name);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return null;
            }
        }

    }
}
